//
//  BaseTableViewController.swift
//  MAGweibo
//
//  Created by MagicaL on 15/7/28.
//  Copyright © 2015年 MagicaL. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController,VistorLoginViewDelegate {
    // 不实现遵循的代理方法在swift中是报错的
    
    /// 添加用户登录标记
    var userLogin = (UserAccount.loadAccount() != nil)
    /// 访客视图
    var vistorView : VistorLoginView?
    override func loadView() {
        
        userLogin ? super.loadView() : setupVistorView()
    }
    
    /// 设置访客视图
    private func setupVistorView() {
    
        vistorView = VistorLoginView()
        vistorView?.delegate = self
        view = vistorView
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorLoginViewWillRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorLoginViewWillLogin")
    
    }
    
    // MARK: - VistorLoginViewDelegate
    func vistorLoginViewWillLogin() {
        
        let nav = UINavigationController(rootViewController: OAuthViewController())
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func vistorLoginViewWillRegister() {
        
        print("注册")
    }
    
}
